using Assets.Core.Jwt;
using Microsoft.AspNetCore.Mvc;
using NFine.Application.User;
using Nucleic.Web.Filters;

namespace Nucleic.Web.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {

        public UserInfo? UserInfo
        {
            get
            {
                var token = HttpContext.Request.Headers["token"].ToString();
                if (string.IsNullOrEmpty(token))
                {
                    return null;
                }
                var result = JwtHelp.CheckToken(token);
                if (result.Success)
                {
                    return result.Data;
                }
                else
                {
                    return null;
                }
            }
        }
        private static readonly string[] Summaries = new[]
        {
        "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
    };

        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        [HttpGet(Name = "GetWeatherForecast")]
        [CheckPermission("")]
        public IEnumerable<WeatherForecast> Get()
        {
            var u = UserInfo;
            _logger.LogInformation("111111");
            _logger.LogError("111111");
            _logger.LogWarning("111111");
            JHRefundApp jHRefund = new JHRefundApp();

            _logger.LogDebug("111111" );
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
            })
            .ToArray();
        }
    }
}